package com.shuaiche.yeguan.util;

import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.shuaiche.yeguan.config.SCAppConfig;

/**
 * Created by baoyinbo on 2017/10/30.
 * 图片url做了防盗处理，需请求头里添加
 * Referer: http://www.shuaiche.com
 */

public class SCImageUrlUtils {

    public static GlideUrl getImgUrl(String picUrl) {
        if (picUrl == null)
            picUrl = "";

        GlideUrl glideUrl = new GlideUrl(appendImageUrl(picUrl),
                new LazyHeaders.Builder()
                        .addHeader("Referer", "https://www.shuaiche.com")
                        .build());

        return glideUrl;
    }

    public static String appendImageUrl(String picUrl) {
        if (picUrl == null) {
            return "";
        }
        if (picUrl.startsWith("http")) {
            return picUrl;
        } else {
            if (picUrl.startsWith("/")){
                return SCAppConfig.IMG_URL_NO_END + picUrl;
            }else {

                return SCAppConfig.IMG_URL + picUrl;
            }
        }
    }

}
